﻿using System;
using System.Data;
using System.Data.SqlClient;
using System.Collections;
using System.Text;
using Portal.Environment;
using Portal.Language;
using Portal.Interface;
using System.Globalization;

namespace Portal.CDSP
{
    public class FBannerWP : WebPart
    {
        public override string WebPartId
        {
            get
            {
                return "WebSite.FBannerWP";
            }
        }

        public override string WebPartFolder
        {
            get
            {
                return "Portal.CDSP";
            }
        }


        public override string Title
        {
            get
            {
                return GetText("Title", "SoYTe-Banner");
            }
        }

        public override ViewCls[] Views
        {
            get
            {
                return new ViewCls[]{
                    new ViewCls("Banner",GetText("Banner","Banner"),0),                  
                };
            }
        }

        [AjaxPro.AjaxMethod]
        public override string ClientRenderWebPart(string BelongSite, string TabModuleId, string ViewName, string HasPorlet, LoadParamCls loadParamCls)
        {
            try
            {
                if (ViewName.Equals("Banner"))
                {
                    return ClientRenderWebPartHeader(TabModuleId, HasPorlet);
                }
                return GetText("ViewNotFound", "Không tìm thấy View [" + ViewName + "]");
            }
            catch (Exception ex)
            {
                return ex.Message.ToString();
            }
        }

        public override string NameSpace
        {
            get
            {
                return "Portal.CDSP";
            }
        }

        public override string ClassName
        {
            get
            {
                return "FBannerWP";
            }
        }



        public override DataTable ReadingDataService(string belongSite, string ActiveLanguage, ref string IdField, ref string SubjectField)
        {
            IdField = "Id";
            SubjectField = "Subject";
            DataTable dtResult = new DataTable();
            dtResult.Columns.Add("Id");
            dtResult.Columns.Add("Subject");
            dtResult.Rows.Add(new object[]{
                "4062D500-1CA2-41A3-B055-04C0C2851243","Banner"
            });
            return dtResult;
        }

        private string ClientRenderWebPartHeader(string TabModuleId, string HasPorlet)
        {
            TabModuleCls TabModuleCls = new TabModuleBLL().CreateModelFromXml(TabModuleId);
            if (TabModuleCls == null) throw new Exception("[" + TabModuleId + "] " + GetText("TabModuleIdNull", "not found!"));
            string AdvImageId = TabModuleCls.Id;
            string belongSite = TabModuleCls.belongSite;
            
            StringBuilder Html = new StringBuilder();
            Html.Append(
            "<div class=\"top-banner-inner\">\n" +
            "			<div class=\"quicksearch\">\n" +
            "				<input type=\"text\" name=\"search_portal\" id=\"search_portal\" class=\"textsearchbox\" value=\"Từ khóa...\" onblur=\"if(this.value=='') this.value='Từ khóa...';\" onfocus=\"if(this.value=='Từ khóa...') this.value='';\" onkeypress=\"javascript:DoPressEnterSearch(event);\">\n" +
            "				<a href=\"javascript:void(0);\" onclick=\"javascript:ClientOnSearchClick();\" class=\"searchbut\">Tìm kiếm</a>\n" +
            "			</div>\n" +
            "		</div>\n");
            return Html.ToString();
        }

        private string ClientRenderWebPartSubBanner(string TabModuleId, string HasPorlet)
        {
            TabModuleCls TabModuleCls = new TabModuleBLL().CreateModelFromXml(TabModuleId);
            if (TabModuleCls == null) throw new Exception("[" + TabModuleId + "] " + GetText("TabModuleIdNull", "not found!"));
            string AdvImageId = TabModuleCls.Id;
            string belongSite = TabModuleCls.belongSite;
            CultureInfo cul = new CultureInfo("vi-VN", true);
            DateTime temp = DateTime.Now.Date;
            string date = temp.ToString("dd/MM/yyyy");
            string SDate = "";
            switch (DateTime.Now.DayOfWeek)
            {
                case DayOfWeek.Monday:
                    SDate = "Thứ hai";
                    break;
                case DayOfWeek.Tuesday:
                    SDate = "Thứ ba";
                    break;
                case DayOfWeek.Wednesday:
                    SDate = "Thứ tư";
                    break;
                case DayOfWeek.Thursday:
                    SDate = "Thứ năm";
                    break;
                case DayOfWeek.Friday:
                    SDate = "Thứ sáu";
                    break;
                case DayOfWeek.Saturday:
                    SDate = "Thứ bảy";
                    break;
                case DayOfWeek.Sunday:
                    SDate = "Chủ nhật";
                    break;
            }
            string Html = "<div class=datetime>" +
                            "<b>" + SDate + ", Ngày " + date + "</b>" +
                            "</div>";


            return Html;
        }

        public override bool AllowFrontService
        {
            get
            {
                return true;
            }
        }
    }
}
